﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="controlChat.ascx.cs" Inherits="chat.chatControl.controlChat" %>
   <script type="text/javascript">
       $(document).ready(
    function() {

        $("#message").change(function(e) {
            // alert('dsfd'); // $(this).blur();
        }); // message.change


        $("form").submit(function() {
            // event.preventDefault();
            //alert('Handler for .submit() called.');


            $.ajax({
                beforeSend: function(XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("Content-Type", "application/json");
                },
                type: "GET",
                url: "./chatControl/processmessage.aspx",
                data: "message=" + $('#message').val() + "&name=" + $('#name').val() + "",
                dataType: "text",
                success: function(msg) { $("#myDiv").text("Data Received: " + msg); }
            }); // end of ajax


            // alert('Handler for .submit() called.');
            // we clean the message textbox and focus it..
            $('#message').val("");
            $('#message').focus();

            return false;

        });
    })

       setInterval(function() {
           $.ajax({
               success: function(request) {
                   $('#chat').html(request);
               },
               url: './chatControl/data.aspx',
               cache: false
           })
       }, 1000)


       function AjaxSucceeded(result) {
           alert(result.d);
       }
       function AjaxFailed(result) {
           alert(result.status + ' ' + result.statusText);
       }  
        
        
</script>
<h1>
    Chat con jquery unobtrusivo.
    </h1>
<div id="chat">
</div>
<form action="process.aspx" method="GET" >    

    <input id="name" name="name" size="10" type="text" /> -
    <input id="message" name="message" size="10" type="text" class="message" />
    <input id="commit" name="commit" value="Enviar" type="submit" />
    
</form>

<div class="footer"><a href="http://www.carakan.com" title="desarrollo web 2.0">original idea from carakan</a></div>
<div class="footer"><a href="http://www.micasoft.net" title="desarrollo web 2.0">final idea from Luis Molina</a></div>
